//
//  ViewController.m
//  IOS-7day
//
//  Created by RIOS on 2018/4/27.
//  Copyright © 2018年 RIOS. All rights reserved.
//

#import "ViewController.h"
#import "MGoods.h"
#import "CellItem.h"
#import "FooterView.h"
#import "HeaderView.h"

@interface ViewController () <UITableViewDelegate,UITableViewDataSource,FooterViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *vTableView;
@property (strong,nonatomic) NSMutableArray *aGoods;

@end

@implementation ViewController

-(NSMutableArray *)aGoods{
    if (_aGoods == nil) {
        _aGoods = [MGoods buildArray];
    }
    return _aGoods;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    FooterView *footerView = [FooterView buildView];
    footerView.delegate = self;
    self.vTableView.tableFooterView = footerView;
    
    HeaderView *headerView = [HeaderView buildView];
    self.vTableView.tableHeaderView = headerView;
    
    
}

-(void)footerViewUpdate:(FooterView *)footerView{
    MGoods *goods = [[MGoods alloc]init];
    goods.icon = @"icon1";
    goods.price = @"1211";
    goods.buyCount = @"2123123";
    goods.title = @"卤肉烧烤";
    [self.aGoods addObject:goods];
    
    [self.vTableView reloadData];
    
    NSIndexPath *index = [NSIndexPath indexPathForRow:self.aGoods.count - 1 inSection:0];
    
    [self.vTableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:true];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.aGoods.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MGoods *goods = self.aGoods[indexPath.row];
    
    CellItem *cell = [CellItem buildWithTableVIew:tableView];
    
    [cell setGoods:goods];
    
    return cell;
    
}


@end
